/**
 * @module 定时任务执行函数
 */
import dayjs from 'dayjs'
import UserTokenService from '@/models/mongo/UserTokenService'
import { consoleLogger } from '../logger'
import { expiredAtFormate } from '../jwt'

// 删除过期的 token记录数据
const deleteExpiredUserTokens = async () => {
  try {
    await UserTokenService.getRepository().deleteMany({
      $or: [{ refresh_token_expired_at: { $lte: dayjs().format(expiredAtFormate) } }, { is_blacked: true }]
    })
    consoleLogger.info('删除过期token记录成功')
  } catch (e) {
    consoleLogger.error('删除过期token记录失败', e)
  }
}

export default [deleteExpiredUserTokens]
